// 提示
export const Toast = (title: string, type: ToastType) => {
  uni.showToast({
    title: title,
    icon: type
  })
}

export const Scan = (): Promise<string | null> => {
  return new Promise((resolve, reject) => {
    // #ifdef H5
    reject('暂不支持H5端扫码')
    // #endif

    // #ifndef MP-WEIXIN
    uni.scanCode({
      success: (res) => {
        resolve(res.result)
      },
      fail: () => {
        Toast('扫描失败', 'none')
        reject(null)
      }
    })
    // #endif
  })
}

export const toPage = (url: string) => {
  uni.navigateTo({
    url: url
  })
}

export const switchPage = (url: string) => {
  uni.switchTab({
    url: url
  })
}

export const backTo = (delta?: number) => {
  uni.navigateBack({
    delta: delta ?? 1
  })
}
